#{extends 'backend_main.html' /}
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" id="id" name="id" value="${sysRole?.id}">
        <div class="layui-form-item">
            <label for="role_name" class="layui-form-label">
                <span class="x-red">*</span>角色名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="role_name" name="role_name" required="" lay-verify="required|role_name" autocomplete="off" class="layui-input"
                       value="${sysRole?.role_name}">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="update" lay-submit="">
                提交
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer','upload','laydate'], function(){
        var $ = layui.jquery;
        var form = layui.form,layer = layui.layer;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#buy_date' //指定元素
        });
        //自定义验证规则
        form.verify({
            role_name: function(value){
                console.log("value=" + value);
                if(value.length < 2){
                    return '角色名称至少得2个字符啊';
                }
            }
        });
        //监听提交
        form.on('submit(update)', function(data){
            console.log(JSON.stringify(data.field));
            //发异步，把数据提交给php
            $.ajax({
                type:"POST",                      //请求类型
                url:"/SystemCenter/roleEdit?v=update",                 //URL
                data:data.field,                  //传递的参数
                dataType:"json",                 //返回的数据类型
                success:function(data){          //data就是返回的json类型的数据
                    console.log(data);
                    layer.alert(data.msg, {icon: 6},function () {
                        parent.window.location.reload();
                    });
                }
            });
            return false;
        });
    });
</script>